package gpar.ep;

import gpar.io.Io;
import gpar.Settings;

import java.util.ArrayList;
import java.util.Enumeration;

/** A candidate which represents a bot. Can easily be mutated as it has a 
* tree structure. Can easily be represented as a Java source code object. 
* @author Maarten Inja */
public class Candidate // implements Expressionable
{
    
    /** Robots class name. */
    private String className; 
    /** Robots package name. Indicates from which generation and EvolutionaryProcess it comes from. */ 
    private String packageName;
    /** The fitness score of this candidate. When < 0 means this Candidate has not been evaluated */
    private int score = -1;

    private ArrayList<Method> methods; 


    public Candidate ()
    {
        methods = new ArrayList<Method> ();

        for (Enumeration e = Settings.eventNamesAndVariables.keys() ; 
            e.hasMoreElements() ;)
        {
            try 
            { 
                String eventName = (String) e.nextElement(); 
                methods.add(new Method(eventName));
            }
            catch(Exception q){System.out.println("THIS IS NOT HAPPENING, Candidate.ctor");}
        }
    }

   
    /** Returns a copy of itself but slightly mutated. Mutation means somewhere a method is
    * changed. This can include; expression tree is altered (this should be familiar); `bnf'
    * grammar is altered. 
    * */
    public Candidate mutate()
    {
        return null;
    }
   
    /** Returns a copy that is the cross mutation of the Candidate supplied as argument. */ 
    public Candidate crossMutate(Candidate candidate)
    {
        return null;
    }


    /** Returns the Java code as a string, which should be compile ready.*/
    public String toCodeString()
    {
        // TODO: toCodeString
        return Io.readFile("Test.java");
        //return "";
    }

    //// {{{ PUBLIC PROPERTIES 

    /** Returns the name which is representative for this candidate. */
    public String getClassName ()
    {
        return "Best";
    }

    public int getScore ()
    {
        return score;
    }
    
    public boolean isEvaluated ()
    {
        return score > 0; 
    }



    // ]}}
}
